const config = require('../../../config/config.local');
const amazonMws = require('amazon-mws')(config.AWSAccessKeyId, config.AWSSecretKey);
const isProduction = process.env.NODE_ENV === 'production';

const getPackageLabels = {};
getPackageLabels.generateOption = function(seller_id, mws_auth_token, marketplaceId, shipmentId, pageType, numberOfPackages=null){
  let baseOption = {
    'Version': '2010-10-01',
    'Action': 'GetPackageLabels',
    'SellerId': seller_id,
    'MWSAuthToken': mws_auth_token,
    'MarketplaceId': marketplaceId,
    'ShipmentId': shipmentId,
    'PageType': pageType,
  };

  if (numberOfPackages)
    baseOption['NumberOfPackages'] = numberOfPackages;

  return baseOption;
};

getPackageLabels._ = function(options) {
  if (!isProduction) {
    return amazonMws.fulfillmentInboundShipment.search(options);
  } else {
    console.error("bot not implemented!")
  }
};

getPackageLabels.getPackageLabels = function(seller_id, mws_auth_token, marketplaceId, shipmentId, pageType, numberOfPackages=null) {
  return this._(this.generateOption(seller_id, mws_auth_token, marketplaceId, shipmentId, pageType, numberOfPackages));
};

module.exports = getPackageLabels;